function myAxios(method='get', url="", params={}){

	format_params = {};

	for(var key in params){
		if(["", undefined].includes(params[key])==false){
			format_params[key] = params[key]
		}
	};

	// axios.interceptors.request.use(function (config) {
	// 	let token = SessionControl.GetStringSession("token");
	// 	if (token) {
	// 		config.headers.accessToken = token;
	// 		 return config;
	// 	}
	// }, function (error) {
	// 	return Promise.reject(error);
	// });


	return axios({
		method: method,
		url: url,
		params: format_params
	});
}

// 请求控制工具
const Requ = (function (){
	const Requ = new Object;

	// 登录请求
	Requ.Login = function(params){
		return myAxios('get', '/api/v1/login', params)
	};

	return Requ;
})();


// Session控制工具
const SessionControl = (function(){
	const control = new Object;

	// 设置string session
	control.SetStringSession = function(key, data){
		sessionStorage.setItem(key, data);
	}

	// 返回string session
	control.GetStringSession = function(key){
		res = sessionStorage.getItem(key);
		return res;
	}

	// 设置json session
	control.SetJsonSession = function(key, data){
		sessionStorage.setItem(key, JSON.stringify(data));
	}

	// 返回json session
	control.GetJsonSession = function(key){
		res = sessionStorage.getItem(key);
		return JSON.parse(res);
	}

	return control;
})()


// URL 控制工具

const URLControl = (function(){

	const control = new Object();

	// 跳转url
	control.JumpUrl = function(url, method, data){
		// token = SessionControl.GetStringSession("token")
		// if(token!=null){
		// 	window.location.href=control.AddUrlArgs(url, {"token":token});
		// }else{
		// 	window.location.href=url;
		// }
		window.location.href=url;
	}

	control.GetUrlArgs = function(search=null){
		if(search==null){
			var url = location.search;
		}else{
			var url = search;
		}
		var theRequest = new Object();
		var sign = url.indexOf("?")
		if (sign != -1) {
			var str = url.substr(sign + 1);
			strs = str.split("&");
			for (var i = 0; i < strs.length; i++) {
				theRequest[strs[i].split("=")[0]] = strs[i].split("=")[1];
			}
		}
		return theRequest;
	}

	control.AddUrlArgs = function(url, data){
		let search = null;
		res = url.split('?')[0]
		if(url.split('?').length>1){
			search =url.split('?')[1];
		}
		args = control.GetUrlArgs(search);
		for(var key in data){
			args[key] = data[key];
		}
		res = res + control.ArgsToSearch(args);
		return res;
	}

	control.ArgsToSearch = function(args){
		let index = 1;
		let search = "?";
		for(var key in args){
			search += key+"="+args[key];
			if(index<Object.keys(args).length){
				console.log(index, Object.keys(args).length);
				search+="&";
			}
			index++;
		}
		return search;
	}
	return control;
})()


const ERRORCODE = {
	"A001": "用户名不存在",
	"A002": "用户名或密码错误",
	"A003": "用户名不能为空",
	"A004": "密码不能为空"
};